<template>
  <div class="collectionchannel">
    <!--采集通道  collectionChannel -->
     <div class="con"> 
         <div class="title-top">
              <span>通道列表</span>
             <div>
               <!-- <div class="mybtn" @click ="addChannel">新增通道</div> -->
                <el-button type="primary"  @click="addChannel">新增通道</el-button>
                <input  type="file" ref="EXCELinput" accept=".xlsx,.xls"  @change="importTemplateEXCELinput"  style="display: none">
                <el-button type="primary"  @click="ExportTemplateEXCEL">导出通道</el-button>
                <el-button type="primary"  @click="daoruEXCELmoban">导入通道</el-button>
                <el-button type="primary" class="last-el-button" @click="exportOperation">导出管理机设备变量信息</el-button>
             </div>
              <!-- generallyvariable -->
              <!-- device -->
         </div>
         <div class="mytable">
                <el-table :data="tableData" height="100%" stripe  style="width: 100%;">
                                        <el-table-column type="index"  width="60" label="序号" align="center"> </el-table-column>
                                        <el-table-column prop="channel_number" width="80" label="通道号" align="center"> 
                                        </el-table-column>
                                        <el-table-column prop="channel_name" min-width="200" label="通道名称"> 
                                        </el-table-column>
                                        <el-table-column prop="channel_type" width="135" label="通道类型" align="center"> 
                                          <template #default="{row}">
                                             <div>
                                               <span v-show="row.channel_type == 1">问答式协议通道</span>
                                               <span v-show="row.channel_type == 0">全双工协议通道</span>
                                               <span v-show="row.channel_type != 1 && row.channel_type != 0">{{row.channel_type}}</span>
                                             </div>
                                          </template>
                                        </el-table-column>
                                        <el-table-column prop="channel_type" width="135" label="端口类型" > 
                                          <template #default="{row}">
                                             <div>
                                               <span v-show="row.port_type == 1">串口：{{row.serial_number}}</span>
                                               <span v-show="row.port_type == 2">TCP服务端</span>
                                               <span v-show="row.port_type == 3">TCP客户端</span>
                                               <span v-show="row.port_type == 4">MQTT客户端</span>
                                               <span v-show="row.port_type == 5">UDP客户端</span>
                                               <span v-show="row.port_type == 6">CAN</span>
                                               <span v-show="row.port_type == 7">DI：{{row.di_number}}</span>
                                               <span v-show="row.port_type == 8">DO：{{row.do_number}}</span>
                                               <span v-show="row.port_type == null"></span>
                                               
                                             </div>
                                          </template>
                                        </el-table-column>
                                        <el-table-column prop="channel_protocol" min-width="170" label="通道规约"> 
                                            <template  #default="{row}">
                                                <div >{{row.channel_protocolZhuan}}</div>
                                          </template>
                                        </el-table-column>
                                        <el-table-column prop="channel_interval" width="110" label="发送间隔(ms)"> 
                                        </el-table-column>
                                        <!-- <el-table-column prop="timeout" width="110" label="接受超时(ms)" align="center">  
                                        </el-table-column> -->
                                        <el-table-column width="200" label="操作" fixed="right" align="center"> 
                                             <template  #default="{row}">
                                                    <div class="mysort">
                                                       <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                                                           <img src="../../assets/btnImg/edit2.png" alt="" style="margin-right:20px" @click.stop="handleCurrentChange(row)">
                                                        </el-tooltip>
                                                         <el-tooltip class="item" effect="dark" content="删除" placement="top">
                                                            <img src="../../assets/btnImg/del2.png" alt="" @click.stop="deletefn(row)">
                                                        </el-tooltip>
                                                           
                                                    </div>
                                                </template>
                                        </el-table-column>
               </el-table>
         </div>
           <!-- 新增/修改 -->
           <el-dialog width="950px" draggable  :title="caozuoType" :close-on-click-modal='false' v-model="addeditflagline">
                    <div class="leftandrightdialog">
                        <div class="leftdio" style="margin-right:20px">
                          <div class="items">
                                <div class="leftname"><span>*</span> 通道号：</div>
                                <div class="elinputdisabled">{{temp.channel_number}}</div>
                            </div>
                            <div class="items">
                               <div class="leftname"><span>*</span> 通道名称：</div>
                                <el-input v-model="temp.channel_name" placeholder="请输入通道名称"></el-input>
                            </div>
                             
                            <div class="items">
                                <div class="leftname"><span>*</span> 通道类型：</div>
                                <el-select v-model="temp.channel_type" placeholder="请输入通道类型" style="width:100%"> 
                                                <el-option
                                                   v-for="item in channelOptions"
                                                   :key="item.value"
                                                   :label="item.label"
                                                   :value="item.value">
                                                   </el-option>
                                 </el-select>
                            </div>
                             <div class="items">
                                <div class="leftname">通道规约：</div>
                                <el-select v-model="temp.channel_protocol" placeholder="请选择通道规约" style="width:100%">
                                                      <el-option
                                                        v-for="item in protocolList"
                                                        :key="item.id"
                                                        :label="item.protocol_alias == '' ? item.name : item.protocol_alias"
                                                        :value="item.id">
                                                        </el-option>
                                </el-select>
                            </div>
                            <div class="items">
                                 <div class="leftname"><span>*</span> 发送间隔：</div>
                                <el-input v-model="temp.channel_interval" placeholder="请输入发送间隔(ms)"></el-input>
                            </div>
                           
                        </div>
                        <div class="leftdio">
                           <div class="radio-type">
                            <div class="left-type">
                                  <div class="myname">端口类型：</div>
                                  <div class="myradio">
                                    <!-- <el-radio v-model="radio" label="10">无</el-radio> -->
                                    <el-radio v-model="radio" label="1">串口</el-radio>
                                    <el-radio v-model="radio" label="2">TCP服务端</el-radio>
                                    <el-radio v-model="radio" label="3">TCP客户端</el-radio>
                                    <!-- <el-radio v-model="radio" label="4">MQTT客户端</el-radio>
                                    <el-radio v-model="radio" label="5">UDP客户端</el-radio>-->
                                    <el-radio v-model="radio" label="6">CAN</el-radio> 
                                    <el-radio v-model="radio" label="7">DI</el-radio>
                                    <el-radio v-model="radio" label="8">DO</el-radio>
                                  </div>
                            </div>
                            <div class="right-tongdao">
                              <div class="myname">通道设置：</div>
                                <el-checkbox v-model="auto_open"></el-checkbox>
                                <span class="tong">通道自动打开</span>
                            </div>
                           </div>
                           <!-- 串口 -->
                           <div class="body-items" v-if="radio == 1">
                              <div class="items">
                                <div class="leftname"><span>*</span> 串口号：</div>
                                   <el-select v-model="serial_number" filterable allow-create>
                                                <el-option
                                                      v-for="item in serial_numberList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                  </el-select>
                              </div>
                              <div class="items">
                                <div class="leftname"><span>*</span> 奇偶校验：</div>
                               <el-select v-model="parity">
                                                <el-option
                                                      v-for="item in parityList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              </div>
                              <div class="items">
                               <div class="leftname "><span>*</span> 数据位：</div>
                                <el-select v-model="data_bits">
                                                <el-option
                                                      v-for="item in data_bitsList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              
                              </div>
                              <div class="items">
                                <div class="leftname"><span>*</span> 波特率：</div>
                                 <el-select v-model="baud_rate">
                                                <el-option
                                                      v-for="item in baud_rateList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                              </div>
                              <div class="items">
                                  <div class="leftname"><span>*</span> 停止位：</div>
                                  <el-select v-model="stop_bits">
                                                  <el-option
                                                        v-for="item in stop_bitsList"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value"
                                                  ></el-option>
                                              </el-select>
                              </div>
                           </div>
                           <!-- TPC服务端 -->
                           <div class="body-items" v-if="radio == 2">
                            <div class="items">
                               <div class="leftname"><span>*</span> 本机地址：</div>
                                <el-input v-model="local_address" placeholder="[IP地址格式]"></el-input>
                                
                            </div>
                             <div class="items">
                               <div class="leftname"><span>*</span> 本机端口：</div>
                                <el-input v-model="local_port" placeholder="[整型数字]"></el-input>
                            </div>
                            <div class="items">
                                <div class="leftname">远方地址：</div>
                                <el-input v-model="remote_address2" placeholder="[IP地址格式]"></el-input>
                            </div>
                           </div>
                           <!-- TPC客户端 -->
                           <div class="body-items" v-if="radio == 3">
                             <div class="items">
                               <div class="leftname "><span>*</span> 远方地址：</div>
                                <el-input v-model="remote_address" placeholder="[IP地址格式]"></el-input>
                            </div>
                             <div class="items">
                                <div class="leftname"><span>*</span> 远方端口：</div>
                                <el-input v-model="remote_port" placeholder="[整型数字]"></el-input>
                            </div>
                           </div>
                           <!-- MQTT客户端 -->
                           <div class="body-items" v-if="radio == 4">
                              <div class="items">
                                <div class="leftname">客户机标识：</div>
                                  <el-input v-model="rightname" placeholder="请输入客户机标识"></el-input>
                              </div>
                              <div class="items">
                                  <div class="leftname">远程地址：</div>
                                  <el-input v-model="rightname" placeholder="[IP地址格式]"></el-input>
                              </div>
                              <div class="items">
                                <div class="leftname">发布主题：</div>
                                  <el-input v-model="rightname" placeholder="请输入发布主题"></el-input>
                                  
                              </div>
                              <div class="items">
                               <div class="leftname ">用户名：</div>
                                <el-input v-model="rightname" placeholder="请输入用户名"></el-input>
                              </div>
                              <div class="items">
                                  <div class="leftname">远程端口：</div>
                                  <el-input v-model="rightname" placeholder="[整型数字]"></el-input>
                              </div>
                              <div class="items">
                                <div class="leftname">订阅：</div>
                                  <el-input v-model="rightname" placeholder="请输入发布主题"></el-input>
                                
                              </div>
                              <div class="items">
                                <div class="leftname ">密码：</div>
                                <el-input v-model="rightname" placeholder="请输入密码"></el-input>
                            </div>
                           </div>
                           <!-- DI口 -->
                           <div class="body-items" v-if="radio == 6">
                            <div class="items">
                                <div class="leftname"><span>*</span>CAN口：</div>
                                <el-input v-model="can_number" placeholder="请输入CAN口"></el-input>
                            </div>
                            <div class="items">
                                <div class="leftname"><span>*</span>波特率：</div>
                                <el-select v-model="can_baud_rate" filterable allow-create>
                                                <el-option
                                                      v-for="item in can_baud_rateList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                                
                            </div>
                           </div>
                           <!-- DI口 -->
                           <div class="body-items" v-if="radio == 7">
                            <div class="items">
                                <div class="leftname"><span>*</span>DI口：</div>
                                <el-input v-model="di_number" placeholder="请输入DI口"></el-input>
                            </div>
                           </div>
                           <!-- DO口 -->
                           <div class="body-items" v-if="radio == 8">
                            <div class="items">
                                <div class="leftname"><span>*</span>DO口：</div>
                                <el-input v-model="do_number" placeholder="请输入DO口"></el-input>
                            </div>
                           </div>
                           
                        </div>
                    </div>
                    <div class="el-loading-mask" v-show="diaisMask">
                                    <div class="el-loading-spinner">
                                    <svg viewBox="25 25 50 50" class="circular">
                                        <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                    </svg>
                           </div>
                     </div>
                   <template #footer>
                        <div class="dialog-footer">
                            <el-button  @click="addeditflagline = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="addpassageway" type="primary">确 定</el-button>
                        </div>
                   </template>
           </el-dialog>
           <!-- 导入EXCEL名称重复提醒 -->
          <el-dialog width="1100px" draggable  title="导入模版(EXCEL)提示"   v-model="daorudiofalseEXCEL" :close-on-click-modal='false'>
                    <div class="choicedio">
                         <div style="color:red;font-size:16px">提示：存在重复名称的数据，只取第一条</div>
                         <div class="mytitle" style="margin-top:8px;margin-bottom:12px">
                                <span></span>通道重复名称的数据列表
                         </div>
                         <div class="diatable" style="width:100%;height:400px">
                            <el-table :data="repeatDataArea" height="100%" stripe  style="width: 100%;">
                                    <el-table-column type="index"  width="50" label="序号" align="center"> </el-table-column>
                                    <el-table-column prop="通道名称"  label="通道名称"> </el-table-column>
                                    <el-table-column prop="端口类型"  label="端口类型"> </el-table-column>
                                    <el-table-column   label="通道类型">
                                      <template #default="{row}">
                                             <div>
                                               <span v-show="row['通道类型'] == 1">问答式协议通道</span>
                                               <span v-show="row['通道类型'] == 0">全双工协议通道</span>
                                               <span v-show="row['通道类型'] != 1 && row['通道类型'] != 0">{{row['通道类型']}}</span>
                                             </div>
                                          </template>
                                       </el-table-column>

                            </el-table>
                             
                         </div>
                    </div>
                      <template #footer>
                            <div class="dialog-footer">
                                 <el-button  @click="daorudiofalseEXCEL = false" type="warning">取消上传</el-button>
                                 <el-button  class="last-el-button"  type="primary" @click="chulihanshu">确 定</el-button>
                            </div>
                    </template> 
         </el-dialog>
          <div class="el-loading-mask" v-show="isMask">
             <div class="el-loading-spinner"><svg viewBox="25 25 50 50" class="circular"> <circle cx="50" cy="50" r="20" fill="none" class="path"></circle></svg></div>
          </div>
     </div>
  </div>
</template>

<script>
import {findchannelconfigAll,channelconfigAdd,deletechannel,channelconfigEdit,exportDevices,batchChannelconfigAdd} from "../../api/dataComparisonApi";
import {infoPtlSo,getDeviceList} from "../../api/Interface";
import {getChannelconfigidleNumber} from "../../api/forwardApi";
import JSZip from 'jszip';
import { saveAs } from 'file-saver';
import * as XLSX from "xlsx"; 
export default {

  data() {
    return {
      addeditflagline:false,//新增修改弹窗
      diaisMask:false,//弹窗的缓冲
      gudingchannel_number:"",
      temp:{
        channel_number:"",
        channel_name:"",
        channel_type:"",
        channel_protocol:"",
        channel_interval:"",
        timeout:"",
      },//新增修改的参数
      rightname:"",
      tableData:[],
      radio:"1",
      checked:true,
      isMask:false,
      input:"",
      protocolList:[],
      channelOptions:[{label:"全双工协议通道",value:0},
                     {label:"问答式协议通道",value:1}],
      portOptions:[
        {label:"串口",value:1},
        {label:"TCP服务端",value:2},
        {label:"TCP客户端",value:3},
        {label:"DI",value:7},
        {label:"DO",value:8},
      ],
      //串口
      serial_number:"", //串口号
      serial_numberList:[
          {
            'label':"1",
            'value':"1",
          },{
            'label':"2",
            'value':"2",
          },
      ], //串口号
      parity:"", //奇偶校验
      parityList:[
         {
            'label':"无校验",
            'value':"0",
          },
          {
            'label':"奇校验",
            'value':"1",
          },
          {
            'label':"偶校验",
            'value':"2",
          },
      ], //奇偶校验
      stop_bits:"", //停止位
      stop_bitsList:[
          {
            'label':"1",
            'value':"1",
          },
          {
            'label':"1.5",
            'value':"1.5",
          },
          {
            'label':"2",
            'value':"2",
          },
      ], //停止位
      baud_rate:"", //波特率
      baud_rateList:[
          {
            'label':"110",
            'value':"110",
          },
          {
            'label':"300",
            'value':"300",
          },
          {
            'label':"600",
            'value':"600",
          },
          {
            'label':"1200",
            'value':"1200",
          },
          {
            'label':"2400",
            'value':"2400",
          },
          {
            'label':"4800",
            'value':"4800",
          },
          {
            'label':"9600",
            'value':"9600",
          },
          {
            'label':"14400",
            'value':"14400",
          },
          {
            'label':"19200",
            'value':"19200",
          },
          {
            'label':"38400",
            'value':"38400",
          },
          {
            'label':"56000",
            'value':"56000",
          },
          {
            'label':"57600",
            'value':"57600",
          },
          {
            'label':"115200",
            'value':"115200",
          },
          {
            'label':"128000",
            'value':"128000",
          },
          {
            'label':"256000",
            'value':"256000",
          },
      ], //波特率
      data_bits:"", //数据位
      data_bitsList:[
          {
            'label':"8",
            'value':"8",
          },
          {
            'label':"7",
            'value':"7",
          },], //数据位
      //TCP服务端
      local_port:"",
      local_address:"",
      remote_address2:"",
      //TCP客户端
      remote_address:"",
      remote_port:"",
      di_number:"",//DI口
      do_number:"",//DO口
      can_number:"",
      can_baud_rate:"",
      can_baud_rateList:[
          {
            'label':"1 Mbps",
            'value':"1000000",
              
          },
          {
            'label':"500 kbps",
            'value':"500000",
          },
          {
            'label':"250 kbps",
            'value':"250000",
          },
          {
            'label':"125 kbps",
            'value':"125000",
          },
          {
            'label':"50kbps及以下",
            'value':"50000",
          },
      ], //波特率
      auto_open:true,//通道自动打开
      
      //表格选中
      nowTableRow:{},
      nowChangnow:false,
      caozuoType:"新增通道",
      deviceArrAll:[],//全部设备
      mywenjianname:"",
      mywenjianneirong:"",
      daorudiofalseEXCEL:false,
      repeatDataArea:[],
      myjsonDataAll:[]
    };
  },

  mounted() {
    this.getDeviceListDataAll()
    this.getinfoPtlSo()
    this.getChannelconfigidleNumberfn()
  },
  watch:{
    // radio(val){
    //   if(val == 7 || val == 8){
    //      this.temp.channel_type = 2
    //   }else {
    //      this.temp.channel_type = 0
    //   }
    // },
  },

  methods: {
    //导出设备变量信息
    exportOperation(){
      // console.log("导出数据");
      this.isMask = true
      exportDevices().then(res => {
        //  console.log("导出信息",res);
         if(res != undefined){
           var arr1 = res
          arr1.generallyvariable =  arr1.generallyvariable.filter(item => item.Name != "")
                var wenjianname = []
                var neirong = []
                for (const key in arr1) {
                    if (arr1.hasOwnProperty(key)) { // 确保属性是对象自身的，而非继承的
                      if(key == 'generallyvariable'){
                        wenjianname.push('generallyvariable.txt')
                        var objs = {
                           'generallyvariable':arr1[key]
                        }
                        neirong.push(JSON.stringify(objs))
                      }else {
                        wenjianname.push('device.txt')
                        var objs = {
                           'device':arr1[key]
                        }
                        neirong.push(JSON.stringify(objs))
                        
                      }
                      
                    }
                  }
                this.mywenjianname = wenjianname
                this.mywenjianneirong = neirong
                this.exportTxtFiles()
         }else {
           this.isMask = false
         }
      })
    },
    async exportTxtFiles() {
      // 管理机设备变量信息202508070849
            var filesname = this.date_format(Date.now())
            // var filesname = "测试"
            const zip = new JSZip();
            const folder = zip.folder(filesname); // 创建文件夹
            this.mywenjianneirong.forEach((item,index) => {
                 folder.file(`${this.mywenjianname[index]}`, item)
            })
            // folder.file("file5.txt", "这是文件5的内容");

            // 生成ZIP文件并下载
            const content = await zip.generateAsync({ type: 'blob' });
            saveAs(content, `${filesname}.zip`); // 下载名为text_files.zip
            this.isMask = false
    },
    date_format(value) { //value就是插值的数据
        if (!value) {
          return ""
        }
        let date = new Date(value);
        let Y = date.getFullYear();
        let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
        let D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());

        let h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
        let m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
        let s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
        let strDate = Y + M + D + h + m + s;
        return `管理机设备变量信息${Y}${M}${D}${h}${m}${s}`
    },
    //获取所有设备
    getDeviceListDataAll(){
          getDeviceList().then(res => {
                this.deviceArrAll = res
          })
    },
    //查询规约
    getinfoPtlSo(){
            infoPtlSo().then(res => {
                // console.log("通道规约",res);
                var wuArr =[{
                      "hide": 1,
                      "id": 0,
                      "name": "无规约",
                      "protocol_name": "无规约",
                      "status": 1,
                      "protocol_alias":"",
                      "suffix": ".so",
                  }]
                  if(res != undefined){
                      this.protocolList = wuArr.concat(res)
                  }
                  this.getfindchannelconfigAll()
            })
    },
    //查询空闲的通道号
    getChannelconfigidleNumberfn(){
      getChannelconfigidleNumber().then(res => { 
         if(res != undefined){
           this.gudingchannel_number = res.idle
         }
      })
    },
    //新增通道编辑
    addChannel() {
       var url = window.location.host.split(':');//页面路径
        this.temp = {
          channel_number:this.gudingchannel_number,
          channel_name:"",
          channel_type:1,
          channel_protocol:this.protocolList.length != 0 ? this.protocolList[0].id : "",
          channel_interval:"100",
          timeout:"100",
        }
        this.serial_number = "1"
        this.parity = "0"
        this.stop_bits = "1"
        this.baud_rate = "9600"
        this.data_bits = "8"
        this.local_port = url[1]
        this.local_address = url[0]
        this.remote_address = ""
        this.remote_address2 = ""
        this.remote_port = ""
        this.caozuoType = '新增通道'
        this.di_number = ""
        this.do_number = ""
        this.can_number = ""
        this.can_baud_rate = "250000"
        this.addeditflagline = true
    },

    //切换通道规约
    guiyue(row){
    var guiyueArr = []
      guiyueArr = this.protocolList.filter(tt => tt.id == row.channel_protocol)
      if(guiyueArr.length != 0 ){
                 row.channel_protocolZhuan = guiyueArr[0].name
              }else {
                 row.channel_protocolZhuan = ""
              }
    },
    //特定行可编辑
    handleEdit(row) {
      // console.log("row",row);
      row.edit = true
      // console.log("this.tableData", this.tableData);
       if(row.port_type == 1){//串口
          this.serial_number = row.serial_number
          this.baud_rate = row.baud_rate
          this.parity = String(row.parity)
          this.data_bits = row.data_bits
          this.stop_bits = row.stop_bits
        }else if(row.port_type == 2){//TCP服务端
           this.local_port = row.local_port
           this.local_address = row.local_address
        }else if(row.port_type == 3){//TPC客户端
            this.remote_port = row.remote_port
            this.remote_address = row.remote_address
        }
      // 进入编辑模式
      // this.tableData[index].edit = true;
    },
    //获取表格列表
    getfindchannelconfigAll(){
      this.isMask = true
        findchannelconfigAll().then(res => {
         this.isMask = false
         if(res == ""){
              this.tableData = []
         }else {
             var guiyueArr = []
             res.forEach(item => {
              item.edit = false
              item.addFlag = 2//判断是新增还是修改 1为新增 2为修改
              guiyueArr = this.protocolList.filter(tt => tt.id == item.channel_protocol)
              if(guiyueArr.length != 0 ){
                 item.channel_protocolZhuan = guiyueArr[0].protocol_alias != "" ?   guiyueArr[0].protocol_alias : guiyueArr[0].name
              }else {
                 item.channel_protocolZhuan = ""
              }
          })
          this.tableData = res
          // console.log("获取表格列表",this.tableData);
         }
          
        })
    },
    //新增修改通道
    addpassageway(){
        if(this.temp.channel_name === ""){
            this.$message({showClose: true,message: '通道名称不能为空',type: 'warning'});
            return
        }
        if(this.temp.channel_number === ""){
            this.$message({showClose: true,message: '通道号不能为空',type: 'warning'});
            return
        }
        if(this.temp.channel_type === ""){
            this.$message({showClose: true,message: '请选择通道类型',type: 'warning'});
            return
        }
        if(this.temp.channel_interval === ""){
            this.$message({showClose: true,message: '发送间隔不能为空',type: 'warning'});
            return
        }
       
       
        
        
       var d = {}
       if(this.radio == 1){
          if(this.serial_number === ""){
            this.$message({showClose: true,message: '串口号不能为空',type: 'warning'});
              return
          }
          if(this.baud_rate === ""){
            this.$message({showClose: true,message: '波特率不能为空',type: 'warning'});
              return
          }
          if(this.parity === ""){
            this.$message({showClose: true,message: '校验位不能为空',type: 'warning'});
              return
          }
          if(this.data_bits === ""){
            this.$message({showClose: true,message: '数据位不能为空',type: 'warning'});
              return
          }
          if(this.stop_bits === ""){
            this.$message({showClose: true,message: '停止位不能为空',type: 'warning'});
              return
          }
          
          d = {
            "channel_name": this.temp.channel_name,
            "channel_number": Number(this.temp.channel_number),
            "channel_type": Number(this.temp.channel_type),
            "channel_protocol": Number(this.temp.channel_protocol),
            "channel_interval": Number(this.temp.channel_interval),
            "port_type": 1,
            "auto_open": this.auto_open ? 1 : 2,
            "device_count": 10,
            "serial_number": Number(this.serial_number),
            "baud_rate": Number(this.baud_rate),
            "parity": Number(this.parity),
            "data_bits":Number( this.data_bits),
            "stop_bits": Number(this.stop_bits)
         }
       }else if(this.radio  == 2){
           if(this.local_port === ""){
            this.$message({showClose: true,message: '本机端口不能为空',type: 'warning'});
              return
          }
           if(this.local_address === ""){
            this.$message({showClose: true,message: '本机地址不能为空',type: 'warning'});
              return
          }
          // if(this.remote_address2 === ""){
          //     this.$message({showClose: true,message: '远方地址不能为空',type: 'warning'});
          //       return
          // }
          d = {
               "channel_name": this.temp.channel_name,
               "channel_number": Number(this.temp.channel_number),
               "channel_type": Number(this.temp.channel_type),
               "channel_protocol": Number(this.temp.channel_protocol),
               "channel_interval": Number(this.temp.channel_interval),
               "port_type": 2,
               "auto_open": this.auto_open ? 1 : 2,
              //  "device_count": 10,
               "local_port": Number(this.local_port),
               "local_address": this.local_address,
               "remote_address":this.remote_address2
            }
       }else if(this.radio == 3){
          if(this.remote_port === ""){
              this.$message({showClose: true,message: '远方端口不能为空',type: 'warning'});
                return
            }
            if(this.remote_address === ""){
              this.$message({showClose: true,message: '远方地址不能为空',type: 'warning'});
                return
            }
           d = {
               "channel_name": this.temp.channel_name,
               "channel_number": Number(this.temp.channel_number),
              "channel_type": Number(this.temp.channel_type),
               "channel_protocol": Number(this.temp.channel_protocol),
               "channel_interval": Number(this.temp.channel_interval),
               "port_type": 3,
               "auto_open": this.auto_open ? 1 : 2,
              //  "device_count": 10,
               "remote_port": Number(this.remote_port),
               "remote_address": this.remote_address
            }
       }else if(this.radio == 6){
          if(this.can_number === ""){
              this.$message({showClose: true,message: 'CAN口不能为空',type: 'warning'});
                return
            }
          d = {
               "channel_name": this.temp.channel_name,
               "channel_number": Number(this.temp.channel_number),
              "channel_type": Number(this.temp.channel_type),
               "channel_protocol": Number(this.temp.channel_protocol),
               "channel_interval": Number(this.temp.channel_interval),
               "port_type": 6,
               "auto_open": this.auto_open ? 1 : 2,
               "baud_rate": Number(this.can_baud_rate),
               "can_number": Number(this.can_number),
            }
       }else if(this.radio == 7){
          if(this.di_number === ""){
              this.$message({showClose: true,message: 'DI口不能为空',type: 'warning'});
                return
            }
          d = {
               "channel_name": this.temp.channel_name,
               "channel_number": Number(this.temp.channel_number),
              "channel_type": Number(this.temp.channel_type),
               "channel_protocol": Number(this.temp.channel_protocol),
               "channel_interval": Number(this.temp.channel_interval),
               "port_type": 7,
               "auto_open": this.auto_open ? 1 : 2,
               "di_number": Number(this.di_number),
            }
       }else if(this.radio == 8){
         if(this.do_number === ""){
              this.$message({showClose: true,message: 'DO口不能为空',type: 'warning'});
                return
            }
         d = {
               "channel_name": this.temp.channel_name,
               "channel_number": Number(this.temp.channel_number),
              "channel_type": Number(this.temp.channel_type),
               "channel_protocol": Number(this.temp.channel_protocol),
               "channel_interval": Number(this.temp.channel_interval),
               "port_type": 8,
               "auto_open": this.auto_open ? 1 : 2,
               "do_number": Number(this.do_number),
            }
          
       }
      // console.log("添加参数",d);
      
      if(this.caozuoType == '新增通道'){//新增
          if(this.radio == 1){
            var findIndexNum = this.tableData.filter(item => item.serial_number == this.serial_number)
            if(findIndexNum.length != 0){
                  this.$message({showClose: true,message: '此串口号已存在！',type: 'warning'});
                  return
            }
          }
          var names = []
          names = this.tableData.filter(item => item.channel_name == this.temp.channel_name)
          if(names.length != 0){
            this.$message({showClose: true,message: '通道名称已重复！！',type: 'warning'});
            return
          }
          

          this.diaisMask = true
          channelconfigAdd(d).then(res => {
            // console.log("新增通道",res);
            this.diaisMask = false
            if(res.code == 200){
                 this.getChannelconfigidleNumberfn()
                 this.addeditflagline = false
                  this.$message({showClose: true,message: '新增成功',type: 'success'});
                  this.getfindchannelconfigAll()
            }else {
                this.$message({showClose: true,message: '新增失败，'+res.msg,type: 'error'});
            }
          })
      }else {
        
         this.diaisMask = true
        d.channel_id = this.nowTableRow.channel_id
           channelconfigEdit(d).then(res => {
            this.diaisMask = false
            // console.log("更新通道",res);
            if(res.code == 200){
                 this.addeditflagline = false
                  this.$message({showClose: true,message: '更新成功',type: 'success'});
                  this.getfindchannelconfigAll()
            }else {
                this.$message({showClose: true,message: '更新失败，'+res.msg,type: 'error'});
            }
          })
      }
      
      
    },
    //删除通道
    deletefn(row){
        var arr1 = this.deviceArrAll.filter(item => item.channel_number == row.channel_number)
        if(arr1.length != 0){
            this.$message({showClose: true,message: '当前通道下有设备，不可删除有设备的通道！',type: 'warning'});
            return
        }
        this.$confirm(`是否要删除此通道？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
               
               deletechannel({'channel_number':row.channel_number}).then(res => {
                  // console.log("删除",res);
                  if(res.code == 200){
                    this.getChannelconfigidleNumberfn()
                     this.$message({showClose: true,message: '删除成功',type: 'success'});
                    this.getfindchannelconfigAll()
                  }else {
                     this.$message.error('删除失败，'+res.msg)
                  }
               }).catch(error => {
                    
               })
              
        
                      
            }).catch(() => {
              // ...
            });
    },
    //选中表格
    handleCurrentChange(val){
        // console.log("表格",val);
        if(val == null){
          return
        }
        this.serial_number = ""
        this.parity = ""
        this.stop_bits = ""
        this.baud_rate = ""
        this.data_bits = ""
        this.local_port = ""
        this.local_address = ""
        this.remote_address = ""
        this.remote_port = ""
        this.caozuoType = `修改通道 (${val.channel_name})`
       
        
        this.temp = {
          channel_number:val.channel_number,
          channel_name:val.channel_name,
          channel_type:val.channel_type,
          channel_protocol:val.channel_protocol,
          channel_interval:val.channel_interval,
          timeout:val.timeout,
        }
        this.nowTableRow = val
        this.radio = String(val.port_type)
        this.auto_open = val.auto_open == 1 ? true : false
        if(val.port_type == 1){//串口
          this.serial_number = val.serial_number
          this.baud_rate = val.baud_rate
          this.parity = JSON.stringify(val.parity)
          this.data_bits = val.data_bits
          this.stop_bits = val.stop_bits
        }else if(val.port_type == 2){//TCP服务端
           this.local_port = val.local_port
           this.local_address = val.local_address
           this.remote_address2 = val.remote_address
        }else if(val.port_type == 3){//TPC客户端
            this.remote_port = val.remote_port
            this.remote_address = val.remote_address
        }else if(val.port_type == 7){
            this.di_number = val.di_number
        }else if(val.port_type == 8){
           this.do_number = val.do_number
        }else if(val.port_type == 6){
           this.can_number = val.can_number
           this.can_baud_rate = String(val.baud_rate)
        }
         this.addeditflagline = true
    },
    //导出设备模版EXCEL
    ExportTemplateEXCEL(){
            // console.log("设备子系列",this.leftTable);
            // port_type 1 2 3 7 8
            // console.log("数据",this.tableData);
            //串口
            var chuangkouArr = this.tableData.filter(item => item.port_type == 1)
            var tableData11 = []
            chuangkouArr.forEach(item => {
                 tableData11.push({
                    // '通道号':String(item.channel_number),
                    '通道名称':String(item.channel_name),
                    '通道类型':String(item.channel_type),
                    '通道规约':String(item.channel_protocol),
                    '发送间隔':String(item.channel_interval),
                    '通道自动打开':item.auto_open == 1 ? '是' : '否',
                    '端口类型':'串口',
                    '串口号':item.serial_number,
                    '奇偶校验':item.parity,
                    '数据位':item.data_bits,
                    '波特率':item.baud_rate,
                    '停止位':item.stop_bits,
                    // auto_open
                 })
            })
           
            // TCP服务端
            var fuwuArr = this.tableData.filter(item => item.port_type == 2)
            var tableData22 = []
            fuwuArr.forEach(item => {
                 tableData22.push({
                    // '通道号':String(item.channel_number),
                    '通道名称':String(item.channel_name),
                    '通道类型':String(item.channel_type),
                    '通道规约':String(item.channel_protocol),
                    '发送间隔':String(item.channel_interval),
                    '通道自动打开':item.auto_open == 1 ? '是' : '否',
                    '端口类型':'TCP服务端',
                    '本机地址':item.local_address,
                    '本机端口':item.local_port,
                    '远方地址':item.remote_address2,
                 })
            })

            // TCP客户端
            var kehuArr = this.tableData.filter(item => item.port_type == 3)
            var tableData44 = []
            kehuArr.forEach(item => {
                 tableData44.push({
                    // '通道号':String(item.channel_number),
                    '通道名称':String(item.channel_name),
                    '通道类型':String(item.channel_type),
                    '通道规约':String(item.channel_protocol),
                    '发送间隔':String(item.channel_interval),
                    '通道自动打开':item.auto_open == 1 ? '是' : '否',
                    '端口类型':'TCP客户端',
                    '远方地址':item.remote_address,
                    '远方端口':item.remote_port,
                 })
            })
            // CAN
            var CANArr = this.tableData.filter(item => item.port_type == 6)
            var tableDataCAN = []
            CANArr.forEach(item => {
                 tableDataCAN.push({
                    // '通道号':String(item.channel_number),
                    '通道名称':String(item.channel_name),
                    '通道类型':String(item.channel_type),
                    '通道规约':String(item.channel_protocol),
                    '发送间隔':String(item.channel_interval),
                    '通道自动打开':item.auto_open == 1 ? '是' : '否',
                    '端口类型':'CAN',
                    'CAN口':item.can_number,
                    '波特率':item.baud_rate,
                    
                 })
            })
            // DI
            var DIArr = this.tableData.filter(item => item.port_type == 7)
            var tableData55 = []
            DIArr.forEach(item => {
                 tableData55.push({
                    // '通道号':String(item.channel_number),
                    '通道名称':String(item.channel_name),
                    '通道类型':String(item.channel_type),
                    '通道规约':String(item.channel_protocol),
                    '发送间隔':String(item.channel_interval),
                    '通道自动打开':item.auto_open == 1 ? '是' : '否',
                    '端口类型':'DI',
                    'DI口':item.di_number,
                 })
            })

            // DO
            var DOArr = this.tableData.filter(item => item.port_type == 8)
            var tableData66 = []
            DOArr.forEach(item => {
                 tableData66.push({
                    // '通道号':String(item.channel_number),
                    '通道名称':String(item.channel_name),
                    '通道类型':String(item.channel_type),
                    '通道规约':String(item.channel_protocol),
                    '发送间隔':String(item.channel_interval),
                    '通道自动打开':item.auto_open == 1 ? '是' : '否',
                    '端口类型':'DO',
                    'DO口':item.do_number,
                 })
            })
            


            var tableData33 =  []
              // 添加数据类型区块
            tableData33.push(['通道类型：', ''])
            tableData33.push(['编码', '名称'])
            this.channelOptions.forEach(item => {
                tableData33.push([item.value, item.label])
            })
            
            // 添加空行
            for (let i = 0; i < 3; i++) {
                tableData33.push(['', ''])
            }
            
            // 添加数据编码区块
            tableData33.push(['奇偶校验：', ''])
            tableData33.push(['编码', '名称'])
            this.parityList.forEach(item => {
                tableData33.push([item.value, item.label])
            })

            // 添加空行
            for (let i = 0; i < 3; i++) {
                tableData33.push(['', ''])
            }
            
            // 添加数据编码区块
            tableData33.push(['通道规约：', ''])
            tableData33.push(['编码', '名称','别名'])
            this.protocolList.forEach(item => {
                tableData33.push([item.id, item.name,item.protocol_alias])
            })
            
            
             // 1. 创建工作簿
            const workbook = XLSX.utils.book_new();

            // 2. 将数组对象转换为工作表
            const worksheet = XLSX.utils.json_to_sheet(tableData11);
            const worksheet2 = XLSX.utils.json_to_sheet(tableData22);
            const worksheet3 = XLSX.utils.json_to_sheet(tableData44);
            const worksheetCAN = XLSX.utils.json_to_sheet(tableDataCAN);
            const worksheet4 = XLSX.utils.json_to_sheet(tableData55);
            const worksheet5 = XLSX.utils.json_to_sheet(tableData66);

            // const worksheet3 = XLSX.utils.json_to_sheet(tableData33);
            const worksheet6 = {};
             // 4. 从A1开始填充数据
            tableData33.forEach((row, rowIndex) => {
                row.forEach((cellValue, colIndex) => {
                const cellAddress = XLSX.utils.encode_cell({ r: rowIndex, c: colIndex })
                // 只有当cellValue不是空字符串时才创建单元格
                if (cellValue !== '') {
                    worksheet6[cellAddress] = { v: cellValue, t: 's' }
                }
                })
            })
            
            // 5. 设置工作表范围（从A1开始）
            const endRow = tableData33.length - 1
            const endCol = Math.max(...tableData33.map(row => row.length)) - 1
            worksheet6['!ref'] = XLSX.utils.encode_range({
                s: { r: 0, c: 0 },  // 从A1开始
                e: { r: endRow, c: endCol }
            })
             // 自定义列宽
            worksheet['!cols'] = [
                { wch: 25 }, 
                { wch: 12 },  
                { wch: 12 },  
                { wch: 10 },  
                { wch: 15 },  
                { wch: 10 },  
                { wch: 10 },  
            ];
             // 自定义列宽
            worksheet2['!cols'] = [
                { wch: 25 }, 
                { wch: 12 },  
                { wch: 12 },    
                { wch: 10 },  
                { wch: 15 },  
                { wch: 18 },  
                { wch: 18 },  
            ];

            // 自定义列宽
            worksheet3['!cols'] = [
                { wch: 25 }, 
                { wch: 12 },  
                { wch: 12 },    
                { wch: 10 },  
                { wch: 15},  
                { wch: 18 },  
                { wch: 18 },  
            ];

            // 自定义列宽
            worksheet4['!cols'] = [
                { wch: 25 }, 
                { wch: 12 },  
                { wch: 12 },    
                { wch: 10 },  
                { wch: 15 },  
                { wch: 10 },  
                { wch: 10 },  
            ];
            // 自定义列宽
            worksheetCAN['!cols'] = [
                { wch: 25 }, 
                { wch: 12 },  
                { wch: 12 },    
                { wch: 10 },  
                { wch: 15 },  
                { wch: 10 },  
                { wch: 10 },  
            ];
            // 自定义列宽
            worksheet5['!cols'] = [
                { wch: 25 }, 
                { wch: 12 },  
                { wch: 12 },    
                { wch: 10 },  
                { wch: 15 },  
                { wch: 10 },  
                { wch: 10 },  
            ];

             // 5. 设置列宽
            worksheet6['!cols'] = [
                { wch: 10 },  // 第一列宽度
                { wch: 40 },   // 第二列宽度
                { wch: 40 }   // 第二列宽度
            ]

            

            // 3. 将工作表添加到工作簿
            XLSX.utils.book_append_sheet(workbook, worksheet, "串口");
            XLSX.utils.book_append_sheet(workbook, worksheet2, "TCP服务端");
            XLSX.utils.book_append_sheet(workbook, worksheet3, "TCP客户端");
            XLSX.utils.book_append_sheet(workbook, worksheetCAN, "CAN");
            XLSX.utils.book_append_sheet(workbook, worksheet4, "DI");
            XLSX.utils.book_append_sheet(workbook, worksheet5, "DO");
            XLSX.utils.book_append_sheet(workbook, worksheet6, "代码表");

            // 4. 生成 Excel 文件并下载
            const excelBuffer = XLSX.write(workbook, { bookType: "xlsx", type: "array" });
            const blob = new Blob([excelBuffer], { type: "application/octet-stream" });
            saveAs(blob, "通道列表信息.xlsx");

    },
    //导入设备模版EXCEL
    daoruEXCELmoban(){
        this.$refs.EXCELinput.click();          
    },
    importTemplateEXCELinput(event){
            const file = event.target.files[0];
            if (!file) return;

            const reader = new FileReader();
            reader.onload = (e) => {
                const data = new Uint8Array(e.target.result);
                const workbook = XLSX.read(data, { type: 'array' });

                // 获取第一个工作表(串口)
                const firstSheetName = workbook.SheetNames[0];
                const worksheet = workbook.Sheets[firstSheetName];

                // 获取第二个工作表(TCP服务端)
                const firstSheetName2 = workbook.SheetNames[1];
                const worksheet2 = workbook.Sheets[firstSheetName2];

                // 获取第二个工作表(TCP客户端)
                const firstSheetName3 = workbook.SheetNames[2];
                const worksheet3 = workbook.Sheets[firstSheetName3];

                 // 获取第二个工作表(CAN)
                const firstSheetNameCAN = workbook.SheetNames[3];
                const worksheetCAN = workbook.Sheets[firstSheetNameCAN];

                // 获取第二个工作表(DI)
                const firstSheetName4 = workbook.SheetNames[4];
                const worksheet4 = workbook.Sheets[firstSheetName4];

                // 获取第二个工作表(DO)
                const firstSheetName5 = workbook.SheetNames[5];
                const worksheet5 = workbook.Sheets[firstSheetName5];

                // 转换为 JSON
                var jsonData = XLSX.utils.sheet_to_json(worksheet, { defval: '' })
                var jsonData2 = XLSX.utils.sheet_to_json(worksheet2, { defval: '' })
                var jsonData3 = XLSX.utils.sheet_to_json(worksheet3, { defval: '' })
                var jsonData4 = XLSX.utils.sheet_to_json(worksheet4, { defval: '' })
                var jsonData5 = XLSX.utils.sheet_to_json(worksheet5, { defval: '' })
                var jsonDataCAN = XLSX.utils.sheet_to_json(worksheetCAN, { defval: '' })

                var jsonDataAll = jsonData.concat(jsonData2,jsonData3,jsonData4,jsonData5,jsonDataCAN).filter(item => item['通道名称'] && item['通道名称'] != '')
                // console.log("全部通道",jsonDataAll);
                this.myjsonDataAll = jsonDataAll
                // 存在相同的通道
                const duplicates = this.findAllDuplicateObjects(jsonDataAll);
                // console.log("存在相同的通道",duplicates);
                this.repeatDataArea = duplicates
                if(duplicates.length != 0){
                  this.daorudiofalseEXCEL = true
                  this.$refs.EXCELinput.value = ""
                    return
                }
                this.chulihanshu()
                
                

               
                
                
            };
            reader.readAsArrayBuffer(file);
    },
    chulihanshu(){
          this.$refs.EXCELinput.value = ""
          this.daorudiofalseEXCEL= false
          var filterDataArea = this.filterUniqueByName(this.myjsonDataAll)
                // console.log("过滤掉的通道",filterDataArea);
                var resultArr = []
                var duplicateName = []
                var arr1 = []
                filterDataArea.forEach((item,index) => {
                      if(item['端口类型'] == '串口') {
                         resultArr.push({
                                  "channel_name": String(item['通道名称']),
                                  // "channel_number": Number(this.gudingchannel_number) + index,
                                  "channel_type": Number(item['通道类型']),
                                  "channel_protocol":item['通道规约'] == '' ? 0 :  Number(item['通道规约']),
                                  "channel_interval": Number(item['发送间隔']),
                                  "port_type": 1,
                                  "auto_open": item['通道自动打开'] == '是' ? 1 : 2,
                                  "device_count": 10,
                                  "serial_number": Number(item['串口号']),
                                  "baud_rate": Number(item['波特率']),
                                  "parity": Number(item['奇偶校验']),
                                  "data_bits":Number(item['数据位']),
                                  "stop_bits": Number(item['停止位'])
                              })
                      }else if(item['端口类型'] == 'TCP服务端'){
                        resultArr.push({
                          "channel_name": String(item['通道名称']),
                          // "channel_number": Number(this.gudingchannel_number) + index,
                          "channel_type": Number(item['通道类型']),
                          "channel_protocol":item['通道规约'] == '' ? 0 :   Number(item['通道规约']),
                          "channel_interval": Number(item['发送间隔']),
                          "port_type": 2,
                          "auto_open": item['通道自动打开'] == '是' ? 1 : 2,
                          "local_port": Number(item['本机端口']),
                          "local_address": item['本机地址'],
                          "remote_address":item['远方地址']
                        })
                        
                      }else if(item['端口类型'] == 'TCP客户端'){
                        resultArr.push({
                            "channel_name": String(item['通道名称']),
                            // "channel_number": Number(this.gudingchannel_number) + index,
                            "channel_type": Number(item['通道类型']),
                            "channel_protocol":item['通道规约'] == '' ? 0 :   Number(item['通道规约']),
                            "channel_interval": Number(item['发送间隔']),
                            "port_type": 3,
                            "auto_open": item['通道自动打开'] == '是' ? 1 : 2,
                            "remote_port": Number(item['远方端口']),
                            "remote_address": item['远方地址']
                          })
                      }else if(item['端口类型'] == 'DI'){
                        resultArr.push({
                            "channel_name": String(item['通道名称']),
                            // "channel_number": Number(this.gudingchannel_number) + index,
                            "channel_type": Number(item['通道类型']),
                            "channel_protocol":item['通道规约'] == '' ? 0 :   Number(item['通道规约']),
                            "channel_interval": Number(item['发送间隔']),
                            "port_type": 7,
                            "auto_open": item['通道自动打开'] == '是' ? 1 : 2,
                            "di_number": Number(item['DI口']),
                          })
                      }else if(item['端口类型'] == 'DO'){
                        resultArr.push({
                            "channel_name": String(item['通道名称']),
                            // "channel_number": Number(this.gudingchannel_number) + index,
                            "channel_type": Number(item['通道类型']),
                            "channel_protocol":item['通道规约'] == '' ? 0 :   Number(item['通道规约']),
                            "channel_interval": Number(item['发送间隔']),
                            "port_type": 8,
                            "auto_open": item['通道自动打开'] == '是' ? 1 : 2,
                            "do_number": Number(item['DO口']),
                          })
                      }else if(item['端口类型'] == 'CAN'){
                        resultArr.push({
                            "channel_name": String(item['通道名称']),
                            // "channel_number": Number(this.gudingchannel_number) + index,
                            "channel_type": Number(item['通道类型']),
                            "channel_protocol":item['通道规约'] == '' ? 0 :   Number(item['通道规约']),
                            "channel_interval": Number(item['发送间隔']),
                            "port_type": 8,
                            "auto_open": item['通道自动打开'] == '是' ? 1 : 2,
                            "can_number": Number(item['CAN口']),
                            "baud_rate":Number(item['波特率'])
                          })
                      }
                })
                // console.log("导入通道",resultArr);
                // return
                if(resultArr.length == 0){
                   return
                }
                   this.isMask = true
                   
                  batchChannelconfigAdd(resultArr).then(res => {
                     this.isMask = false
                      if(res.code == 200){
                          this.getChannelconfigidleNumberfn()
                          this.$message({showClose: true,message: '导入成功',type: 'success'});
                          this.getfindchannelconfigAll()
                       }
                  })
                this.$refs.EXCELinput.value = ""
    },
    
    //找出数组对象名字属性相同的数据
    findAllDuplicateObjects(arr) {
            var typename = '通道名称'
            const nameCount = arr.reduce((acc, obj) => {
                 acc[obj[typename]] = (acc[obj[typename]] || 0) + 1;
                 return acc;
            }, {});
            return arr.filter(obj => nameCount[obj[typename]] > 1);
    },
    //过滤掉重复的数据
    filterUniqueByName(arr) {
            var typename = '通道名称'
            const seen = {};
            return arr.filter(item => {
                const name = item[typename];
                if (!seen[name]) {
                seen[name] = true;
                return true;
                }
                return false;
            });
    },
  },
  filters: {
      // 转换时间戳
      "date_format": function(value) { //value就是插值的数据
        if(!value) {
          return ""
        }
        return value
      },
    }
};
</script>
<style lang="scss" scoped>
    
    .collectionchannel {
         width: 100%;
         height: 100%;
         position: relative;
         .con {
             width: 100%;
             height: 100%;
             background-color: #fff;
            //  padding: 12px;
             box-sizing: border-box;
           .title-top {
             width: 100%;
             height: 42px;
             display: flex;
             align-items: center;
             justify-content: space-between;
             border-bottom: 1px solid #E6E6E6;
             padding: 0px 12px;
             box-sizing: border-box;
             span {
                 font-size: 14px;
                 color: #1A1A1A;
             }
             
           }
           .mytable {
              width: 100%;
              height: calc(100% - 80px);
              padding: 0px 12px;
              box-sizing: border-box;
              margin-top: 12px;
              .mysort {
                 display: flex;
                 align-items: center;
                 justify-content: center;
              }
              .mysort-text {
               color:#2178F1;
              }
           }
           .edit-info {
             width: 100%;
             height: calc(100% - 480px);
            //  background-color: red;
             margin-top: 12px;
             padding: 0px 12px;
             box-sizing: border-box;
             
             .info-con {
                  width: 100%;
                  height: 100%;
                  border: 1px solid #E6E6E6;
                border-radius: 4px;
                background-color: #FAFAFA;
                padding: 20px 20px 12px 20px;
                box-sizing: border-box;
                .infotitle {
                     font-size: 13px;
                     color: #1A1A1A;
                }
               
                .info-body {
                     width: 100%;
                     height: calc(100% - 102px);
                     .body-items {
                         width: 100%;
                         height: 100%;
                         display: flex;
                         flex-wrap: wrap;
                        align-content: flex-start;
                         .body-item {
                            width: 440px;
                            height: 44px;
                            margin-right: 40px;
                            display: flex;
                            align-items: center;
                             .leftname {
                                 width: 72px;
                                 height: 100%;
                                 text-align: right;
                                 line-height: 44px;
                                 color: #666666;
                                 font-size: 12px;
                                 margin-right: 8px;
                             }
                             :deep(.el-input__inner) {
                                 background-color: transparent;
                             }
                             .tips {
                                 font-size: 12px;
                                 color: #666666;
                                 margin-left: 8px;
                             }
                             .tong {
                             margin-left: 4px;
                             color: #1A1A1A;
                             font-size: 12px;
                         }


                         }
                     }
                }
                .bottom-btn {
                     width: 100%;
                     display: flex;
                     align-items: center;
                     justify-content: center;
                     .quxiao {
                         margin-left: 8px;
                         color: #666666;
                         background-color: #fff;
                         border: 1px solid #cccccc;
                     }
                }
             }
           }
        }
    }
    .infoitems {
       display: flex;
       align-items: center;
       .items {
         width: 50%;
       }
       .itemright {
         margin-right: 20px;
       }
       
    }
    .body-items {
      margin-top: 10px;
      .infoitems {
        .items {
                    width: 33%;
                  }
      }
           
       }
     .radio-type {
                     width: 100%;
                    //  height: 30px;
                     display: flex;
                     align-items: center;
                     flex-wrap: wrap;
                      .myname {
                            width: 60px;
                            text-align: right;
                            font-size: 12px;
                            color: #666666;
                            // margin-right: 8px;
                            position: relative;
                         }
                     .left-type {
                         display: flex;
                        //  align-items: center;
                        //  flex-wrap: wrap;
                        //  margin-right: 40px;
                         .myname {
                            top: 7px;
                            white-space: nowrap;
                         }
                     }
                     .myradio {
                        display: flex;
                         align-items: center;
                         flex-wrap: wrap;
                     }
                     .right-tongdao {
                         display: flex;
                         align-items: center;
                         position: relative;
                         top: -1px;
                         .tong {
                             margin-left: 4px;
                             color: #1A1A1A;
                             font-size: 12px;
                         }
                     }
                }
</style>